package com.leet.code.lcof;

public class Code15 {
    public static void main(String[] args) {
        System.out.println(new Code15().hammingWeight(9));
        int i = 0b11111111111111111111111111111101;
//        i = i & 0b01111111111111111111111111111111;
//        System.out.println(i);
        System.out.println(new Code15().hammingWeight(i));
    }

    // you need to treat n as an unsigned value
    public int hammingWeight(int n) {
        int sum = 0;
//        if (n < 0) {
//            n = n & 0b01111111111111111111111111111111;
//            sum = 1;
//        }

        while (n != 0) {
            sum = sum + (n & 1);
            n = n >>> 1;
        }
        return sum;
    }

}
